package com.vctgo.accountSet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.accountSet.domain.TbAddress;
import com.vctgo.accountSet.service.ITbAddressService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 单位所在地Controller
 *
 * @author vctgo
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/address")
public class TbAddressController extends BaseController
{
    @Autowired
    private ITbAddressService tbAddressService;

    /**
     * 查询单位所在地列表
     */
    @RequiresPermissions("accountSet:address:list")
    @GetMapping("/list")
    public AjaxResult list(TbAddress tbAddress)
    {
        IPage<TbAddress> list = tbAddressService.selectTbAddressPage(tbAddress);
        return AjaxResult.success(list);
    }

    /**
     * 导出单位所在地列表
     */
    @RequiresPermissions("accountSet:address:export")
    @Log(title = "单位所在地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAddress tbAddress)
    {
        List<TbAddress> list = tbAddressService.selectTbAddressList(tbAddress);
        ExcelUtil<TbAddress> util = new ExcelUtil<TbAddress>(TbAddress.class);
        util.exportExcel(response, list, "单位所在地数据");
    }

    /**
     * 获取单位所在地详细信息
     */
    @RequiresPermissions("accountSet:address:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbAddressService.selectTbAddressById(id));
    }

    /**
     * 新增单位所在地
     */
    @RequiresPermissions("accountSet:address:add")
    @Log(title = "单位所在地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAddress tbAddress)
    {
        return toAjax(tbAddressService.insertTbAddress(tbAddress));
    }

    /**
     * 修改单位所在地
     */
    @RequiresPermissions("accountSet:address:edit")
    @Log(title = "单位所在地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAddress tbAddress)
    {
        return toAjax(tbAddressService.updateTbAddress(tbAddress));
    }

    /**
     * 删除单位所在地
     */
    @RequiresPermissions("accountSet:address:remove")
    @Log(title = "单位所在地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbAddressService.deleteTbAddressByIds(ids));
    }
}
